#ifndef CCurrencyH
#define CCurrencyH

#include <vcl.h>
#include "eic.h"



//extern PACKAGE_EIC AnsiString __fastcall EICMontantToChaine(const Currency &Montant);

class PACKAGE_EIC CCurrency
{
private:
  Currency m_Montant;
  bool m_Vide;
  inline AnsiString __fastcall GetSQL() const
    {
      return m_Vide ? AnsiString("NULL") : EICMontantToChaine(m_Montant);
    }
  inline AnsiString __fastcall GetText() const
    {
      return m_Vide ? EmptyStr : CurrToStrF( m_Montant, ffCurrency, 2);
    }
  inline AnsiString __fastcall GetTextNonFormate() const
    {
      return m_Vide ? EmptyStr : AnsiString(m_Montant);
    }
public:
  //Les constructeurs/destructeur
  inline __fastcall CCurrency()  //CCurrency CCur;
    {
      m_Vide = true;
    }
  inline __fastcall CCurrency(const int Val)  //CCurrency CCur(i);
    {
      if (Val == L_NS)
        m_Vide = true;
      else
        {
          m_Vide = false;
          m_Montant = Val;
        }
    }
  inline __fastcall CCurrency(const double Val)  //CCurrency CCur(d);
    {
      if (Val == D_NS)
        m_Vide = true;
      else
        {
          m_Vide = false;
          m_Montant = Val;
        }
    }
  inline __fastcall CCurrency(const AnsiString &Val)  //CCurrency CCur(s);
    {
      if (Val.IsEmpty())
        m_Vide = true;
      else
        {
          m_Vide = false;
          AnsiString s = Val;
          for(int i = 1; i <= s.Length(); i++)
          {
            if( (s[i] == ' ') || ((unsigned char)s[i] == 0xA0)) s.Delete(i,1);
          }
          m_Montant = s;
        }
    }
  inline __fastcall CCurrency(const Currency &Val)  //CCurrency CCur(c);
    {
      m_Vide = false;
      m_Montant = Val;
    }
  inline __fastcall CCurrency(const CCurrency &Val)  //CCurrency CCur(CCur2);
    {
      m_Vide = Val.m_Vide;
      m_Montant = Val.m_Montant;
    }
  virtual __fastcall ~CCurrency()
    {
    }
  //Les accesseurs
  inline __fastcall operator int() const  //i = CCur;
    {
      return m_Vide ? L_NS : (int)m_Montant;
    }
  inline __fastcall operator double() const  //d = CCur;
    {
      return m_Vide ? D_NS : (double)m_Montant;
    }
  inline __fastcall operator Currency() const  //c = Currency(CCur);
    {
      return m_Montant;
    }
  inline __fastcall operator AnsiString() const  //s = AnsiString(CCur);
    {
      return GetText();
    }
  __property AnsiString SQL = {read = GetSQL};  //s = CCur.SQL;
  __property AnsiString Text = {read = GetText};  //s = CCur.Text;
  __property AnsiString TextNonFormate = {read = GetTextNonFormate};  //s = CCur.TextNonFormate;
  __property bool       Vide = {read = m_Vide};
  inline void __fastcall Clear()  //CCur.Clear();
    {
      m_Montant = 0.0;
      m_Vide = true;
    }
  inline bool __fastcall IsEmpty() const  //if (CCur.IsEmpty())
    {
      return m_Vide;
    }
  //Les opérateurs d'affectation
  inline CCurrency & __fastcall operator =(int Val)  //CCur = i;
    {
      if (Val == L_NS)
        Clear();
      else
        {
          m_Vide = false;
          m_Montant = Val;
        }
      return *this;
    }
  inline CCurrency & __fastcall operator =(double Val)  //CCur = d;
    {
      if (Val == D_NS)
        Clear();
      else
        {
          m_Vide = false;
          m_Montant = Val;
        }
      return *this;
    }
  inline CCurrency & __fastcall operator =(const AnsiString &Val)  //CCur = s;
    {
      if (Val.IsEmpty())
        Clear();
      else
        {
          m_Vide = false;
          m_Montant = Val;
        }
      return *this;
    }
  inline CCurrency & __fastcall operator =(const Currency &Val)  //CCur = c;
    {
      m_Montant = Val;
      m_Vide = false;
      return *this;
    }
  inline CCurrency & __fastcall operator =(const CCurrency &Val)  //CCur = CCur2;
    {
      m_Montant = Val.m_Montant;
      m_Vide = Val.m_Vide;
      return *this;
    }
  //Les opérateurs de comparaison
  inline bool __fastcall operator ==(int Val) const  //if (CCur == i)
    {
      if (Val == L_NS)
        return m_Vide;
      return m_Vide ? false : (m_Montant == Val);
    }
  inline bool __fastcall operator ==(double Val) const  //if (CCur == d)
    {
      if (Val == D_NS)
        return m_Vide;
      return m_Vide ? false : (m_Montant == Val);
    }
  inline bool __fastcall operator ==(const Currency &Val) const  //if (CCur == c)
    {
      return m_Montant == Val;
    }
  inline bool __fastcall operator ==(const CCurrency &Val) const  //if (CCur == CCur2)
    {
      return (m_Vide == Val.m_Vide) && (m_Montant == Val.m_Montant);
    }
  inline friend bool __fastcall operator ==(int ValL,const CCurrency &ValC)  //if (i == CCur)
    {
      return ValC.operator ==(ValL);
    }
  inline friend bool __fastcall operator ==(double ValD,const CCurrency &ValC)  //if (d == CCur)
    {
      return ValC.operator ==(ValD);
    }
  inline friend bool __fastcall operator ==(const Currency &Val,const CCurrency &ValC)  //if (c == CCur)
    {
      return ValC.operator ==(Val);
    }
  inline bool __fastcall operator !=(int Val) const  //if (CCur != i)
    {
      if (Val == L_NS)
        return !m_Vide;
      return m_Vide ? true : (m_Montant != Val);
    }
  inline bool __fastcall operator !=(double Val) const  //if (CCur != d)
    {
      if (Val == D_NS)
        return !m_Vide;
      return m_Vide ? true : (m_Montant != Val);
    }
  inline bool __fastcall operator !=(const Currency &Val) const  //if (CCur == c)
    {
      return m_Montant != Val;
    }
  inline bool __fastcall operator !=(const CCurrency &Val) const  //if (CCur == CCur2)
    {
      return (m_Vide != Val.m_Vide) || (m_Montant != Val.m_Montant);
    }
  inline friend bool __fastcall operator !=(int ValL,const CCurrency &ValC)  //if (i != CCur)
    {
      return ValC.operator !=(ValL);
    }
  inline friend bool __fastcall operator !=(double ValD,const CCurrency &ValC)  //if (d != CCur)
    {
      return ValC.operator !=(ValD);
    }
  inline friend bool __fastcall operator !=(const Currency &Val,const CCurrency &ValC)  //if (c != CCur)
    {
      return ValC.operator !=(Val);
    }
  inline bool __fastcall operator <(int Val) const  //if (CCur < i)
    {
      int Val2 = (Val == L_NS ? 0 : Val);
      return m_Montant < Val2;
    }
  inline bool __fastcall operator <(double Val) const  //if (CCur < d)
    {
      double Val2 = (Val == D_NS ? 0.0 : Val);
      return m_Montant < Val2;
    }
  inline bool __fastcall operator <(const Currency &Val) const  //if (CCur < c)
    {
      return m_Montant < Val;
    }
  inline bool __fastcall operator <(const CCurrency &Val) const  //if (CCur < CCur2)
    {
      return m_Montant < Val.m_Montant;
    }
  inline friend bool __fastcall operator <(int ValL,const CCurrency &ValC)  //if (i < CCur)
    {
      return ValC.operator >=(ValL);
    }
  inline friend bool __fastcall operator <(double ValD,const CCurrency &ValC)  //if (d < CCur)
    {
      return ValC.operator >=(ValD);
    }
  inline friend bool __fastcall operator <(const Currency &Val,const CCurrency &ValC)  //if (c < CCur)
    {
      return ValC.operator >=(Val);
    }
  inline bool __fastcall operator <=(int Val) const  //if (CCur <= i)
    {
      int Val2 = (Val == L_NS ? 0 : Val);
      return m_Montant <= Val2;
    }
  inline bool __fastcall operator <=(double Val) const  //if (CCur <= d)
    {
      double Val2 = (Val == D_NS ? 0.0 : Val);
      return m_Montant <= Val2;
    }
  inline bool __fastcall operator <=(const Currency &Val) const  //if (CCur <= c)
    {
      return m_Montant <= Val;
    }
  inline bool __fastcall operator <=(const CCurrency &Val) const  //if (CCur <= CCur2)
    {
      return m_Montant <= Val.m_Montant;
    }
  inline friend bool __fastcall operator <=(int ValL,const CCurrency &ValC)  //if (i <= CCur)
    {
      return ValC.operator >=(ValL);
    }
  inline friend bool __fastcall operator <=(double ValD,const CCurrency &ValC)  //if (d <= CCur)
    {
      return ValC.operator >=(ValD);
    }
  inline friend bool __fastcall operator <=(const Currency &Val,const CCurrency &ValC)  //if (c <= CCur)
    {
      return ValC.operator >=(Val);
    }
  inline bool __fastcall operator >(int Val) const  //if (CCur > i)
    {
      int Val2 = (Val == L_NS ? 0 : Val);
      return m_Montant > Val2;
    }
  inline bool __fastcall operator >(double Val) const  //if (CCur > d)
    {
      double Val2 = (Val == D_NS ? 0.0 : Val);
      return m_Montant > Val2;
    }
  inline bool __fastcall operator >(const Currency &Val) const  //if (CCur > c)
    {
      return m_Montant > Val;
    }
  inline bool __fastcall operator >(const CCurrency &Val) const  //if (CCur > CCur2)
    {
      return m_Montant > Val.m_Montant;
    }
  inline friend bool __fastcall operator >(int ValL,const CCurrency &ValC)  //if (i > CCur)
    {
      return ValC.operator <(ValL);
    }
  inline friend bool __fastcall operator >(double ValD,const CCurrency &ValC)  //if (d > CCur)
    {
      return ValC.operator <(ValD);
    }
  inline friend bool __fastcall operator >(const Currency &Val,const CCurrency &ValC)  //if (c > CCur)
    {
      return ValC.operator <(Val);
    }
  inline bool __fastcall operator >=(int Val) const  //if (CCur >= i)
    {
      int Val2 = (Val == L_NS ? 0 : Val);
      return m_Montant >= Val2;
    }
  inline bool __fastcall operator >=(double Val) const  //if (CCur >= d)
    {
      double Val2 = (Val == D_NS ? 0.0 : Val);
      return m_Montant >= Val2;
    }
  inline bool __fastcall operator >=(const Currency &Val) const  //if (CCur >= c)
    {
      return m_Montant >= Val;
    }
  inline bool __fastcall operator >=(const CCurrency &Val) const  //if (CCur >= CCur2)
    {
      return m_Montant >= Val.m_Montant;
    }
  inline friend bool __fastcall operator >=(int ValL,const CCurrency &ValC)  //if (i >= CCur)
    {
      return ValC.operator <=(ValL);
    }
  inline friend bool __fastcall operator >=(double ValD,const CCurrency &ValC)  //if (d >= CCur)
    {
      return ValC.operator <=(ValD);
    }
  inline friend bool __fastcall operator >=(const Currency &Val,const CCurrency &ValC)  //if (c >= CCur)
    {
      return ValC.operator <=(Val);
    }
  //Les opérateurs d'ajout
  inline CCurrency __fastcall operator +(int Val) const  //CCur2 = CCur + i;
    {
      CCurrency ValRetour(*this);
      if (Val != L_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant += Val;
        }
      return ValRetour;
    }
  inline CCurrency __fastcall operator +(double Val) const  //CCur2 = CCur + d;
    {
      CCurrency ValRetour(*this);
      if (Val != D_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant += Val;
        }
      return ValRetour;
    }
  inline CCurrency __fastcall operator +(const Currency &Val) const  //CCur2 = CCur + c;
    {
      CCurrency ValRetour(*this);
      ValRetour.m_Vide = false;
      ValRetour.m_Montant += Val;
      return ValRetour;
    }
  inline CCurrency __fastcall operator +(const CCurrency &Val) const  //CCur2 = CCur + CCur3;
    {
      CCurrency ValRetour(Val);
      if (!m_Vide)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant += m_Montant;
        }
      return ValRetour;
    }
  inline friend CCurrency __fastcall operator +(int ValL,const CCurrency &ValC)  //CCur2 = i + CCur;
    {
      CCurrency ValRetour(ValC);
      if (ValL != L_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant += ValL;
        }
      return ValRetour;
    }
  inline friend CCurrency __fastcall operator +(double ValD,const CCurrency &ValC)  //CCur2 = d + CCur;
    {
      CCurrency ValRetour(ValC);
      if (ValD != D_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant += ValD;
        }
      return ValRetour;
    }
  inline friend CCurrency __fastcall operator +(const Currency &Val,const CCurrency &ValC)  //CCur2 = c + CCur;
    {
      CCurrency ValRetour(ValC);
      ValRetour.m_Vide = false;
      ValRetour.m_Montant += Val;
      return ValRetour;
    }
  inline CCurrency & __fastcall operator ++()  //CCur++; et ++CCur;
    {
      m_Vide = false;
      m_Montant++;
      return *this;
    }
  inline CCurrency & __fastcall operator +()  //+CCur;
    {
      return *this;
    }
  inline CCurrency & __fastcall operator +=(int Val)  //CCur += i;
    {
      return *this = *this + Val;
    }
  inline CCurrency & __fastcall operator +=(double Val)  //CCur += d;
    {
      return *this = *this + Val;
    }
  inline CCurrency & __fastcall operator +=(const Currency &Val)  //CCur += c;
    {
      m_Montant += Val;
      m_Vide = false;
      return *this;
    }
  inline CCurrency & __fastcall operator +=(const CCurrency &Val)  //CCur += CCur2;
    {
      return *this = *this + Val;
    }
  //Les opérateurs de soustraction
  inline CCurrency __fastcall operator -(int Val) const  //CCur2 = CCur - i;
    {
      CCurrency ValRetour(*this);
      if (Val != L_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant -= Val;
        }
      return ValRetour;
    }
  inline CCurrency __fastcall operator -(double Val) const  //CCur2 = CCur - d;
    {
      CCurrency ValRetour(*this);
      if (Val != D_NS)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant -= Val;
        }
      return ValRetour;
    }
  inline CCurrency __fastcall operator -(const Currency &Val) const  //CCur2 = CCur - c;
    {
      CCurrency ValRetour(*this);
      ValRetour.m_Vide = false;
      ValRetour.m_Montant -= Val;
      return ValRetour;
    }
  inline CCurrency __fastcall operator -(const CCurrency &Val) const  //CCur2 = CCur - CCur3;
    {
      CCurrency ValRetour(*this);
      if (!Val.m_Vide)
        {
          ValRetour.m_Vide = false;
          ValRetour.m_Montant -= Val.m_Montant;
        }
      return ValRetour;
    }
  inline friend CCurrency __fastcall operator -(int ValL,const CCurrency &ValC)  //CCur2 = i - CCur;
    {
      return CCurrency(ValL) - ValC;
    }
  inline friend CCurrency __fastcall operator -(double ValD,const CCurrency &ValC)  //CCur2 = d - CCur;
    {
      return CCurrency(ValD) - ValC;
    }
  inline friend CCurrency __fastcall operator -(const Currency &Val,const CCurrency &ValC)  //CCur2 = c - CCur;
    {
      return CCurrency(Val) - ValC;
    }
  inline CCurrency & __fastcall operator --()  //CCur--; et --CCur;
    {
      m_Vide = false;
      m_Montant--;
      return *this;
    }
  inline CCurrency __fastcall operator -() const  //-CCur;
    {
      CCurrency ValRetour(*this);
      ValRetour.m_Montant = -ValRetour.m_Montant;
      return ValRetour;
    }
  inline CCurrency & __fastcall operator -=(int Val)  //CCur -= i;
    {
      return *this = *this - Val;
    }
  inline CCurrency & __fastcall operator -=(double Val)  //CCur -= d;
    {
      return *this = *this - Val;
    }
  inline CCurrency & __fastcall operator -=(const Currency &Val)  //CCur += c;
    {
      m_Montant -= Val;
      m_Vide = false;
      return *this;
    }
  inline CCurrency & __fastcall operator -=(const CCurrency &Val)  //CCur -= CCur2;
    {
      return *this = *this - Val;
    }
  //Les opérateurs de multiplication
  CCurrency __fastcall operator *(int Multiplicateur) const  //CCur2 = CCur * i;
    {
      CCurrency ValRetour;
      if (m_Vide || (Multiplicateur == L_NS))
        return ValRetour;
      ValRetour.m_Vide = false;
      ValRetour.m_Montant = m_Montant * Multiplicateur;
      return ValRetour;
    }
  CCurrency __fastcall operator *(double Multiplicateur) const  //CCur2 = CCur * d;
    {
      CCurrency ValRetour;
      if (m_Vide || (Multiplicateur == D_NS))
        return ValRetour;
      ValRetour.m_Vide = false;
      ValRetour.m_Montant = m_Montant * Multiplicateur;
      return ValRetour;
    }
  inline CCurrency __fastcall operator *(const Currency &Multiplicateur) const  //CCur2 = CCur * c;
    {
      CCurrency ValRetour;
      if (m_Vide)
        return ValRetour;
      ValRetour.m_Vide = false;
      ValRetour.m_Montant = m_Montant * Multiplicateur;
      return ValRetour;
    }
  inline CCurrency __fastcall operator *(const CCurrency &Multiplicateur) const  //CCur2 = CCur * CCur3;
    {
      CCurrency ValRetour;
      if (m_Vide || Multiplicateur.Vide)
        return ValRetour;
      ValRetour.m_Vide = false;
      ValRetour.m_Montant = m_Montant * Multiplicateur.m_Montant;
      return ValRetour;
    }
  inline friend CCurrency __fastcall operator *(int Multiplicateur,const CCurrency &Val)  //CCur2 = i * CCur;
    {
      return Val.operator *(Multiplicateur);
    }
  inline friend CCurrency __fastcall operator *(double Multiplicateur,const CCurrency &Val)  //CCur2 = d * CCur;
    {
      return Val.operator *(Multiplicateur);
    }
  inline friend CCurrency __fastcall operator *(const Currency &Multiplicateur,const CCurrency &Val)  //CCur2 = c * CCur;
    {
      return Val.operator *(Multiplicateur);
    }
  CCurrency & __fastcall operator *=(int Multiplicateur)  //CCur *= i;
    {
      if (m_Vide)
        return *this;
      if (Multiplicateur == L_NS)
        {
          m_Montant = 0.0;
          m_Vide = true;
          return *this;
        }
      m_Montant *= Multiplicateur;
      return *this;
    }
  CCurrency & __fastcall operator *=(double Multiplicateur)  //CCur *= d;
    {
      if (m_Vide)
        return *this;
      if (Multiplicateur == D_NS)
        {
          m_Montant = 0.0;
          m_Vide = true;
          return *this;
        }
      m_Montant *= Multiplicateur;
      return *this;
    }
  CCurrency & __fastcall operator *=(const Currency &Multiplicateur)  //CCur *= c;
    {
      if (m_Vide)
        return *this;
      m_Montant *= Multiplicateur;
      return *this;
    }
  CCurrency & __fastcall operator *=(const CCurrency &Multiplicateur)  //CCur *= CCur2;
    {
      if (m_Vide)
        return *this;
      if (Multiplicateur.Vide)
        {
          m_Montant = 0.0;
          m_Vide = true;
          return *this;
        }
      m_Montant *= Multiplicateur.m_Montant;
      return *this;
    }
  //Les opérateurs de division
  CCurrency __fastcall operator /(int Diviseur) const;  //CCur2 = CCur / i;
  CCurrency __fastcall operator /(double Diviseur) const;  //CCur2 = CCur / d;
  CCurrency __fastcall operator /(const Currency &Diviseur) const  //CCur2 = CCur / c;
    {
      CCurrency ValRetour;
      ValRetour.m_Vide = m_Vide;
      ValRetour.m_Montant = m_Montant / Diviseur;
      return ValRetour;
    }
  CCurrency __fastcall operator /(const CCurrency &Diviseur) const;  //CCur2 = CCur / CCur3;
  CCurrency & __fastcall operator /=(int Diviseur);  //CCur /= i;
  CCurrency & __fastcall operator /=(double Diviseur);  //CCur /= d;
  CCurrency & __fastcall operator /=(const Currency &Diviseur)  //CCur2 /= c;
    {
      m_Montant /= Diviseur;
      return *this;
    }
  CCurrency & __fastcall operator /=(const CCurrency &Diviseur);  //CCur2 /= CCur;
};



#endif

